/*
 * @Author: szx
 * @Date: 2022-04-27 14:06:49
 * @LastEditTime: 2022-04-27 14:20:28
 * @Description:
 * @FilePath: \leetcode\800-899\883\883.js
 */
/**
 * @param {number[][]} grid
 * @return {number}
 */
var projectionArea = function (grid) {
    const n = grid.length;
    let res1 = 0,
        res2 = 0,
        res = 0;
    for (let i = 0; i < n; i++) {
        (res1 = 0), (res2 = 0);
        for (let j = 0; j < n; j++) {
            res1 = Math.max(res1, grid[i][j]);
            res2 = Math.max(res2, grid[j][i]);
            if (grid[i][j] != 0) res++;
        }
        res += res1 + res2;
    }
    return res;
};
